#include<bits/stdc++.h>
using namespace std;
long long mod=1e9+7;
long long a[500000+5],sum;
inline long long quick_mod(long long b,long long p,long long mod) {
	register long long tmp=b;
    register long long ans=1;
	while(p!=0){
		if(p%2!=0){
			ans=(1ll*ans%mod
                *1ll*tmp%mod)
                %mod;
        }
		tmp=(1ll*tmp%mod
            *1ll*tmp%mod)
            %mod;
		
        p/=2;
	}
	return ans%mod;
}
inline long long read(){
	long long x;
	scanf("%lld",&x);
	return x;
}
long long IN() {
	char ch;
	long long a=0;
	while((ch=getchar())==' '||ch=='\n');
		a+=ch-'0';
	while((ch=getchar())!=' '&&ch!='\n') {
		a*=10;
		a+=ch-'0';
	}
	return a;
}
int main() {
	ios::sync_with_stdio(false);
	register long long n=IN(),m=IN();
	a[0]=1,a[1]=a[0];
	for(register long long i=2; i<=m; i++) a[i]=((1ll*a[i-1]*i)%mod+mod)%mod;	
	for(register long long j=0; j<=n; j++) {
		register long long set=(  a[n]%mod
						*quick_mod((a[n-j]%mod+mod)%mod
						*a[j]%mod,mod-2,mod)%mod
						*a[m-j]%mod
						*quick_mod(a[m-n],mod-2,mod)%mod
					  )%mod;
		sum=(j%2!=0)?(sum-set)%mod:(sum+set)%mod;
	}
	register long long ans=(( 1ll*sum
                    *a[m]%mod
                    *1ll*quick_mod(a[m-n],mod-2,mod)%mod+mod
                  )%mod+mod)%mod;
	printf("%lld\n",(ans+mod)%mod);
    return mod;
	//((ans%mod+mod)%mod+mod)%mod
}